package com.dingdang.controller;

import com.dingdang.data.Result;
import com.dingdang.em.ResultEnum;
import com.dingdang.service.EsSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/search")
@Api(value = "商品的搜索")
public class SearchController {

    @Resource
    private EsSearchService esSearchService;

    @PostMapping("/participle")
    @ApiOperation(value = "商品的模糊(分词搜索)")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "title",value = "查询的字段",paramType = "query",required = true)
    )
    public Result searchInfo(@RequestParam("title") String title,
                             @RequestParam(defaultValue = "1")Integer pageNum,
                             @RequestParam(defaultValue = "10")Integer pageSize){
        Map<String, Object> map = esSearchService.selectInfo(title,pageNum,pageSize);

        return Result.response(ResultEnum.SUCCESS).setData(map);
    }

    @PostMapping("/selectCondition")
    @ApiOperation(value = "车辆的条件查询")
    public Result selectCondition(@RequestParam("carInformationId") Long carInformationId,@RequestParam("carTypeId") Long carTypeId,
                                  @RequestParam("kilometersTraveled")Long kilometersTraveled, @RequestParam("assessmentId")String assessmentId,
                                  @RequestParam("transferNum")String transferNum, @RequestParam("carDisplacement")String carDisplacement){
        Map<String, Object> map = esSearchService.selectCondition(carInformationId, carTypeId, kilometersTraveled, assessmentId, transferNum, carDisplacement);
        return Result.response(ResultEnum.SUCCESS).setData(map);
    }
}
